package com.xing.demo;

import java.util.Scanner;

public class switch计算器 {
    public static void main(String[] args) {

        //使用switch实现计算器操作
        Scanner input = new Scanner(System.in);
        System.out.println("请输入第一个数字");
        int num1 = input.nextInt();
        System.out.println("请输入第二个数字");
        int num2 = input.nextInt();
        System.out.println("请输入一个运算符");
        String ope = input.next();
        int result=0;
        switch (ope){
            case "+":
                result=num1+num2;
                break;
            case "-":
                result=num1-num2;
                break;
            case "*":
                result=num1*num2;
                break;
            case "/":
                if(num2==0){
                    System.out.println("被除数不能为0");
                }else {
                    result=num1/num2;
                }
                break;
        }
        System.out.println("结果是： "+result);

    }
}
